/**
 * Created by zhu on 2015/11/1.
 */
var category;
var mydiv;


$(function () {
    mydiv = $('#my_select');

    mydiv.on('click', "select", function () {
        var length = mydiv.children('select').length - 1;
        var index = $(this).index();
        for (var i = length; i > index; i--) {
            mydiv.children('select')[i].remove();
        }
        //$('#my_select').children('select').attr("name","");
        var tempValue = $(this).children('option:selected').val();
        judge(tempValue);
    });

    $.get(host + "/orginno", function (data) {
        loadData(data);
    });

});

function loadData(data) {

    category = data.list;
    $("#select_first").empty();
    $.each(category, function (i, item) {
        if (item.parentno == 0) {
            $("#select_first").append('<option value="' + item.orginno + '">' + item.areaname + '</option>');
        }
    });

}

function judge(tempValue) {
    var temp = '<select  style="width: 100px;height: 30px;" >';
    var flag = 0;
    $.each(category, function (i, item) {
        if (item.parentno == tempValue) {
            temp += '<option value="' + item.orginno + '">' + item.areaname + '</option>';
            flag++;
        }
    });
    temp += '</select>';
    if (flag > 0) {
        mydiv.append(temp);
    }


}

function getCategory(){
    mydiv = $('#my_select');
    var x = $(mydiv.children('select')[mydiv.children('select').length - 1]).children('option:selected').val();
    //alert(x);
    return x;
}



